#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>

</style>
#end

#define js()
<script type="text/javascript">
    layui.use(['table', 'layer'], function () {
        var table = layui.table
            , layer = layui.layer
            , $ = layui.jquery
            , form = layui.form;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: 'full-150'    //容器高度
            , cols: [[                  //标题栏
                {type: 'numbers', fixed: true, unresize: true}

                , {field: 'birthday', title: '出生日期', minWidth: 100,sort:true}
                , {field: 'phone', title: '手机号码', minWidth: 120,sort:true}
                , {field: 'politics', title: '政治面貌', minWidth: 100,sort:true}
                , {field: 'nation', title: '民族', minWidth: 60,sort:true}
                , {field: 'nationality', title: '国籍', minWidth: 60,sort:true}
                , {field: 'education', title: '学历', minWidth: 60,sort:true}
                , {field: 'othername', title: '曾用名', minWidth:100,sort:true}
                , {field: 'duty', title: '职务', minWidth: 60,sort:true}
                , {field: 'residence', title: '长期居住地址', minWidth: 200,sort:true}
                , {field: 'mail', title: '邮箱', minWidth: 150,sort:true}
                , {field: 'resume', title: '工作简历', minWidth: 120,sort:true}
                , {field: 'children', title: '子女情况', minWidth: 120,sort:true}
                , {field: 'maritalstatus', title: '婚姻状况', minWidth: 120,sort:true}
                , {field: 'census', title: '户籍', minWidth: 120,sort:true}
                , {field: 'occupation', title: '职业', minWidth: 100,sort:true}
                , {field: 'createTime', title: '创建时间', minWidth: 150,sort:true}
                , {fixed: 'right', title: '操作', minWidth: 200, align: 'center', toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , url: '#(ctxPath)/app/affected_group/tableData'
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , done: function (res, curr, count) {
            }
        });

        table.on('tool(dateTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    util.sendAjax({
                        type: 'POST',
                        url: '#(ctxPath)/app/affected_group/delete',
                        data: {id: data.id},
                        loadFlag: true,
                        success: function (data) {
                            layer.close(index);
                            reloadTable($('#name').val(), $('#des').val());
                        },
                        unSuccess: function (data) {
                            layer.close(index);
                        }
                    })
                });
            } else if (obj.event === 'edit') {
                pop_show('影响群体', '#(ctxPath)/app/affected_group/update?id=' + data.id, '', '', function () {
                    reloadTable($('#name').val(), $('#des').val());
                });
            } else if (obj.event === 'use') {
                util.sendAjax({
                    type: 'POST',
                    url: '#(ctxPath)/app/affected_group/use',
                    data: {id: data.id},
                    loadFlag: true,
                    success: function (data) {
                        reloadTable($('#name').val());
                    }
                });
            } else if (obj.event === 'unuse') {
                layer.confirm('确定禁用该影响群体吗', function (index) {
                    util.sendAjax({
                        type: 'POST',
                        url: '#(ctxPath)/app/affected_group/unuse',
                        data: {id: data.id},
                        loadFlag: true,
                        success: function (data) {
                            layer.close(index);
                            reloadTable($('#name').val());
                        },
                        unSuccess: function (data) {
                            layer.close(index);
                        }
                    });
                });
            }
        });

        $("#add").click(function () {
            pop_show('添加影响群体', '#(ctxPath)/app/affected_group/add', '', '', function () {
                reloadTable($('#name').val(), $('#des').val());
            });
        });

        reloadTable = function (name, des) {
            table.reload('dateTable', {
                url: '#(ctxPath)/app/affected_group/tableData'
                , where: {name: name, des: des} //设定异步数据接口的额外参数
            });
        };

        form.on('submit(search)', function (data) {
            reloadTable(data.field.name, data.field.des);
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });


</script>
#end

#define content()
<div class="layui-fluid">
    <form id="searchForm" class="layui-form x-center" action="">
        <div class="layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" placeholder="影响群体名称" class="layui-input"/>
                </div>
                <div class="layui-input-inline" style="width : 80px">
                    <button class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </div>
    </form>
    <hr>
    <div class="layui-row">
        <div class="layui-btn-group">
            #shiroHasPermission('/app/affected_group/add')
            <button id="add" class="layui-btn layui-btn-small">添加影响群体</button>
            #end
        </div>
        <table id="dateTable" lay-filter="dateTable"></table>
    </div>
</div>

<script type="text/html" id="barOption">
    #shiroHasPermission('/app/affected_group/update')
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    #end

    #[[
    {{#  if(d.status == '0'){ }}
    ]]#
    #shiroHasPermission('/app/affected_group/use')
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="use">启用</a>
    #end
    #[[
    {{#  } }}
    ]]#

    #[[
    {{#  if(d.status == '1'){ }}
    ]]#
    #shiroHasPermission('/app/affected_group/unuse')
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="unuse">禁用</a>
    #end
    #[[
    {{#  } }}
    ]]#

    #shiroHasPermission('/app/affected_group/delete')
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    #end
</script>
#end